package cn.zyq.ykb.controller.mgt.cps;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.cps.Cps;
import cn.zyq.ykb.service.cps.CpsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * cps-物料Controller
 *
 * @author SystemAuth
 * @date 2024-01-22
 */

@RestController(value = "MgtCpsController")
@RequestMapping("/mgt/cps")
@Api(tags = "cps-物料接口")
public class CpsController extends BaseController {

    @Autowired
    private CpsService cpsService;

    /**
     * 查询cps-物料列表
     */
    @ApiOperation(value = "列表", response = Cps.class)
    @PreAuthorize("@ss.hasPermi('ykb:cps:list')")
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.cpsService.selectCpsList(pageParam);
    }

     /**
      * 导出cps-物料列表
      */
     @ApiOperation(value = "导出")
     @PreAuthorize("@ss.hasPermi('ykb:cps:export')")
     @Log(title = "cps-物料" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, @RequestBody PageParam pageParam) {
         List<Cps> list = cpsService.selectCpsAllList(pageParam);
         ExcelUtil<Cps> util = new ExcelUtil<Cps>(Cps. class);
         util.exportExcel(response, list, "cps-物料数据");
     }

    /**
     * 获取cps-物料详细信息
     */
    @ApiOperation(value = "详情", response = Cps.class)
    @PreAuthorize("@ss.hasPermi('ykb:cps:query')")
    @GetMapping(value = "/{cpsID}")
    public Object getInfo(@PathVariable("cpsID") Integer cpsID) {
        return this.cpsService.selectCpsByCpsID(cpsID);
    }
    /**
     * 获取cps-物料详细信息
     */
    @ApiOperation(value = "详情", response = Cps.class)
    @PreAuthorize("@ss.hasPermi('ykb:cps:query')")
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.cpsService.selectCpsByServiceID(serviceID);
    }

    /**
     * 新增cps-物料
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('ykb:cps:add')")
    @Log(title = "cps-物料", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody Cps cps) {
        return this.cpsService.insertCps(cps);
    }

    /**
     * 修改cps-物料
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('ykb:cps:edit')")
    @Log(title = "cps-物料", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody Cps cps) {
        return this.cpsService.updateCps(cps);
    }

    /**
     * 删除cps-物料
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('ykb:cps:remove')")
    @Log(title = "cps-物料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cpsIDs}")
    public Object remove(@PathVariable Integer[] cpsIDs) {
        return this.cpsService.deleteCpsByCpsIDs(cpsIDs);
    }
}
